package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.exception.BaseException;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.domain.LanguageKey;
import com.ruoyi.system.domain.params.LanguageKeyParams;
import com.ruoyi.system.domain.vo.LanguageKeyVo;
import com.ruoyi.system.mapper.LanguageKeyMapper;
import com.ruoyi.system.service.ILanguageKeyService;
import com.ruoyi.system.service.ILanguageValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author qy
 * @date 2023/3/15 14:34
 */
@Service
public class LanguageKeyServiceImpl implements ILanguageKeyService {

    @Autowired
    private LanguageKeyMapper languageKeyMapper;

    @Autowired
    private ILanguageValueService languageValueService;
    @Override
    public LanguageKey getById(Long id) {
        return null;
    }

    @Override
    public List<LanguageKeyVo> queryList(LanguageKeyParams languageKeyParams) {
        return languageKeyMapper.queryList(languageKeyParams);
    }

    @Override
    public LanguageKey save(LanguageKey languageKey) {
        return null;
    }

    @Override
    @Transactional
    public void editLanguageKey(String oldCode, String newCode, String keyType) {
        String username = SecurityUtils.getUsername();
        LanguageKey byObj = this.getByCode(oldCode);
        if (byObj == null) {
            throw new BaseException("语言code不存在");
        }
        LanguageKey languageKey = new LanguageKey();
        languageKey.setUpdateTime(DateUtils.getNowDate());
        languageKey.setUpdateBy(username);
        languageKey.setType(keyType);
        languageKey.setCode(newCode);
        this.updateById(languageKey,byObj.getId());
        languageValueService.updateLanguageKey(oldCode, newCode, username);
    }

    @Override
    public LanguageKey getByCode(String code) {
        return languageKeyMapper.getByCode(code);
    }

    @Override
    public int delete(Long[] ids) {
        return 0;
    }

    @Override
    public void updateById(LanguageKey languageKey, Long id) {
        languageKeyMapper.updateById(languageKey,id);
    }
}
